package com.flute.framework.autoprompt;

import java.io.Serializable;

public class Token implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -7816203622916783076L;
	private char[] originalText;
	private double[] priority;

	public Token(int length) {
		this.priority = new double[length];
	}

	public Token(String text, double priority, int length) {
		setOriginalText(text);
		this.priority = new double[length];
		this.priority[0] = priority;
	}

	public void updatePriority(double priority, int pos) {
		if (pos <= this.priority.length && pos >= 1) {
			this.priority[pos - 1] = priority;
		}
	}

	public String getOriginalText() {
		return new String(originalText);
	}

	public void setOriginalText(String text) {
		this.originalText = text.toCharArray();
	}

	public TokenPriority getPriority() {
		TokenPriority tp = TokenPriority.getInstance();
		for (int i = 0; i < priority.length; i++) {
			tp.addPriority(priority[i], i + 1);
		}
		return tp;
	}

	public void setPriority(TokenPriority priority) {
		this.priority = priority.getPriority();
	}

	public String toString() {
		return new String(originalText) + ":" + getPriority().getPriorityString();
	}

}
